<?php
namespace app\admin\controller;

use app\common\model\Gather as GatherModel;
/**
 * 法会和义工控制器
 * Class Gather
 * @package app\index\controller
 */
class Gather extends Base
{
    /**
     * [getIndex  法会活动列表]
     * @param 1社会活动 2义工招募
     * @return mixed|\think\response\Json
     * @author [C。]
     */
    public function getIndex()
    {
        $param = input('param.');
        $model = new GatherModel;
        $map = [];
        $user = $this->user;
        try{
            if(!empty($param['title'])){
                $map['title'] = ['like', "%" . $param['title'] . "%"];;
            }
            $map['type'] = $param['type'];
            $map['states'] = 1;
            $list = $model->getAllData($map,'id','id,title');
        }catch(\Exception $e){
            return admin_json(-1, '获取失败'.$e->getMessage());
        }
        if($param['type'] == 1){
            $name = '社会活动';
        }elseif($param['type'] == 2){
            $name = '义工招募';
        }
        writelog('查看'.$name.'列表',1,$user);
        return admin_json(1, '获取成功',$list);
    }
    /**
     * [getIndex  法会活动列表]
     * @param 1社会活动 2义工招募
     * @return mixed|\think\response\Json
     * @author [C。]
     */
    public function edit()
    {
        $param = input('param.');
        $model = new GatherModel;
        $user = $this->user;
        try{
            $gather = $model->findData($param['id'],'id','type');
            if($gather['type'] == 1){
                $name = '社会活动';
            }else{
                $name = '义工招募';
            }
            $model->editData($param);
        }catch(\Exception $e){
            return admin_json(-1, '修改失败'.$e->getMessage());
        }
        writelog('编辑'.$name,1,$user);
        return admin_json(1, '修改成功');
    }
}